package com.mammoth.Bodybuilding.controller.web;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.mammoth.Bodybuilding.service.IRegionService;

import io.swagger.annotations.ApiOperation;
/**
 * 
 * @title : RegionController
 * @description : 区域 控制器
 * @company : com.mammoth.Bodybuilding.controller.mobile
 * @project Mammoth
 * @author xingzhaojun
 * @date 2018年4月24日 下午15:46:01
 */
@RestController
@RequestMapping(value="/region")
public class RegionController {
	
	
	/** 注入区域service **/
	@Autowired
	private IRegionService regionService;
	
	/**
	 * 获取所有省份信息
	 * @return
	 */
	@ApiOperation(value="获取省份信息",notes="获取所有省份信息")
	@GetMapping(value="/province")
	@ResponseBody
	@Cacheable("province")
	public String getAllProvince() {
		return regionService.getProvince().toString();
	}
	/**
	 * 根据省份id获取市信息
	 * @param provinceId 省份id
	 * @return
	 */
	@ApiOperation(value="获取城市信息",notes="根据省份id获取城市信息")
	@GetMapping(value="/city")
	@ResponseBody
	@Cacheable("city")
	public String getCityForProvince(@RequestParam @Valid Long provinceId) {
		return regionService.getCity(provinceId).toString();
	};
	
	/**
	 * 根据城市id获取区县信息
	 * @param cityId
	 * @return
	 */
	@Cacheable("area")
	@ApiOperation(value="获取区县信息",notes="根据城市id获取区县信息")
	@GetMapping(value="/area")
	@ResponseBody
	public String getAreaForCity(@RequestParam @Valid Long cityId) {
		return regionService.getArea(cityId).toString();
	};
}
